

/*
 * BlogEditorPanel.java
 *
 * Created on Jan 30, 2011, 10:56:52 PM
 */

package com.remoteblogger.blogeditor;

import com.remoteblogger.wordpress.WPGlobalUser;
import java.util.HashMap;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;

/**
 *
 * @author prasath
 */
public class BlogEditorPanel extends javax.swing.JPanel {

    HashMap params = new HashMap();

    /** Creates new form BlogEditorPanel */
    public BlogEditorPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleField = new javax.swing.JTextField();
        contentScrollPane = new javax.swing.JScrollPane();
        contentPane = new javax.swing.JEditorPane();
        publishButtom = new javax.swing.JButton();

        titleField.setText(org.openide.util.NbBundle.getMessage(BlogEditorPanel.class, "BlogEditorPanel.titleField.text")); // NOI18N

        contentScrollPane.setViewportView(contentPane);

        publishButtom.setText(org.openide.util.NbBundle.getMessage(BlogEditorPanel.class, "BlogEditorPanel.publishButtom.text")); // NOI18N
        publishButtom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                publishButtomActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(contentScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(titleField, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(publishButtom, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(53, 53, 53))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(contentScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(publishButtom)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void publishButtomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_publishButtomActionPerformed

        //checks wheter there are any user blogs
        if(WPGlobalUser.getInstance().getClient().isEmpty()) {
            NotifyDescriptor d = new NotifyDescriptor.Message("There no blogs created");
            DialogDisplayer.getDefault().notify(d);
            
        } else {
            // return object is not useful for validation
            params.put("description", titleField.getText());
            params.put("title", contentPane.getText());
            //currenlty supports one blog, and publish is set true
            WPGlobalUser.getInstance().getClient().get(0).createPost(params, true);
        }

    }//GEN-LAST:event_publishButtomActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JEditorPane contentPane;
    private javax.swing.JScrollPane contentScrollPane;
    private javax.swing.JButton publishButtom;
    private javax.swing.JTextField titleField;
    // End of variables declaration//GEN-END:variables

}
